package com.yozinga.util;

import com.yozinga.BaseActivity;
import com.yozinga.R;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

public class AlertDialogManager {
	/**
	 * Function to display simple Alert Dialog
	 * @param context - application context
	 * @param title - alert dialog title
	 * @param message - alert message
	 * @param status - success/failure (used to set icon)
	 * 				 - pass null if you don't want icon
	 * */

	private Context mContext;
	private AlertListener mAlertListener;
	public void showAlertDialog(Context context, String title, String message,
			Boolean status,String buttonText) {
		mContext = context;
		if(mContext!=null){

			AlertDialog alertDialog = new AlertDialog.Builder(mContext).create();

			// Setting Dialog Title
			alertDialog.setTitle(title);

			// Setting Dialog Message
			alertDialog.setMessage(message);

			if(status != null)
				// Setting alert dialog icon
				alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);

			// Setting OK Button
			alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, buttonText, new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					BaseActivity baseActivity = (BaseActivity) mContext;
					baseActivity.finish();
				}
			});

			// Showing Alert Message
			alertDialog.show();
		}

	}
	
	public interface AlertListener{
		public void positiveClicked(String offerId,String redeemCode);
		public void negativeClicked();
	}
	public void showAlertDialog1(Context context, String title, String message,
			Boolean status,String buttonText) {
		mContext = context;
		if(mContext!=null){

			AlertDialog alertDialog = new AlertDialog.Builder(mContext).create();

			// Setting Dialog Title
			alertDialog.setTitle(title);

			// Setting Dialog Message
			alertDialog.setMessage(message);

			if(status != null)
				// Setting alert dialog icon
				alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);

			// Setting OK Button
			alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, buttonText, new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					
				}
			});

			// Showing Alert Message
			alertDialog.show();
		}

	}
	
	public void showAlertDialog2(Context context, String title, final String offerId,final String message,
			Boolean status,String buttonText,String buttonText1,AlertListener alertListener) {
		mContext = context;
		mAlertListener = alertListener;
		if(mContext!=null){

			AlertDialog alertDialog = new AlertDialog.Builder(mContext).create();

			// Setting Dialog Title
			alertDialog.setTitle(title);

			// Setting Dialog Message
			alertDialog.setMessage(message);

			if(status != null)
				// Setting alert dialog icon
				alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);

			// Setting OK Button
			alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, buttonText, new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					mAlertListener.positiveClicked(offerId,message);
			
				}
			});
			alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, buttonText1, new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					mAlertListener.negativeClicked();
				}
			});

			// Showing Alert Message
			alertDialog.show();
		}

	}
}
